<template>
  <div class="index">
    <div class="nav">
      <div class="side">
        <i class="iconfont icon-caidanlan"></i>
        <i class="iconfont icon-sousuo"></i>        
      </div>
      <h2>BELLERIS</h2>
      <div class="side">
        <i class="iconfont icon-gerenxinxi-copy"></i>
        <i class="iconfont icon-gouwudai"></i>        
      </div>
    </div>
    <div class="type">
      {{type}}
    </div>
    <div class="filter">
      <div class="filter-item match">
        <pop-window @getclickItem="handleClick($event)">{{ select }}</pop-window>
      </div>
      <div class="filter-item result">{{list.length}}&nbsp;resylts</div>
    </div>
    <div class="list">
      <div v-for="(item,index) in list" :key="index" class="list-item">
        <img :src="require(`@/assets/image/${item.img}`)" alt="" />
        <p class="content">{{item.title}}</p>
        <p class="content">
          <span class="new-price">${{item.newPrice}}</span>
          <span class="old-price">${{item.oldPrice}}</span>
        </p>
      </div>
    </div>
  </div>
</template>
<script>
import PopWindow from '../components/popWindow.vue';
export default {
  data() {
    return {
      type:'Ms coat',
      select:'Best Match',
      list:[
        {
          img:'coat1.png',
          title:'Product Title',
          newPrice:255,
          oldPrice:667
        },
        {
          img:'coat2.png',
          title:'Product Title',
          newPrice:235,
          oldPrice:999
        },
        {
          img:'coat3.png',
          title:'Product Title',
          newPrice:198,
          oldPrice:988
        },
        {
          img:'coat4.png',
          title:'Product Title',
          newPrice:366,
          oldPrice:657
        }
      ]
    }
  },
  components:{
    PopWindow
  },
  methods:{
    //获取子组件传过来的排序方法
    handleClick(value){
      this.select = value;
        this.list = this.list.sort(this.compareHtoL(value,'newPrice'))
     
    },
    //按价格排序
     compareHtoL(howtoSort,value){
      return function(a,b){
        var value1 = a[value]
        var value2 = b[value]
        if(howtoSort === 'Price - High To Low'){
          return value2 - value1
        }else if(howtoSort === 'Price - Low To High'){
          return value1 - value2
        }
      }
    },
  }
}
</script>
<style lang="less" scoped>
.index{
  .nav{
    padding:0 1rem;
    font-size: 1.4rem;
    color: #000000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 3.5rem;
    border-bottom: 0.05rem solid #D9D9D9;
    h2{
      font-weight: bold;
    }
    .side{
      width: 4rem;
      display: flex;
      justify-content: space-between;
      .iconfont{
        font-size: 1.5rem;
        color: #000000;
      }
    }
  }
  .type{
    font-size: 1.2rem;
    width:100%;
    font-weight: bold;
    height: 6rem;
    line-height: 6rem;
    text-align: center;
  }
  .filter{
    display: flex;
    border: 0.1rem solid #D9D9D9;
    height: 3rem;
    justify-content: space-between;
    .filter-item{
      flex: 1;
      text-align: center;
      line-height: 3rem;
      font-weight: bold;
    }
    .match{
      border-right: 0.1rem solid #D9D9D9;
    }

  }
  .list{
    padding: 1rem;
    -moz-column-count:2; /* Firefox */
    -webkit-column-count:2; /* Safari 和 Chrome */
    column-count:2;
    .list-item{
      text-align: center;
      width: 100%;
      padding-bottom: 2rem;
      img{
        width: 100%;
      }
      .content{
        margin-top: 1rem;
        color: #666666;
        .new-price{
          color: #000000;
          margin-right: 0.5rem;
          font-weight: bold;
          font-size: 1.1rem;
        }
        .old-price{
          color: #999999;
          font-size: 1.1rem;
        }
      }
    }
  }
}

</style>